//
//  activeViewController.m
//  UI20_豆瓣电影storyBoard
//
//  Created by 王阳阳 on 16/1/4.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "activeViewController.h"
#import "UIImageView+WebCache.h"
#import "NetWorkHandler.h"
#import "activimodel.h"
@interface activeViewController ()
@property (nonatomic, strong)NSArray *daraArr;
@property (nonatomic, assign)NSTimer *timer;
@end

@implementation activeViewController



- (IBAction)dianji:(id)sender {
    
    NSLog(@"%@",NSHomeDirectory());
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject stringByAppendingPathComponent:@"a.plist"];
    NSMutableArray  *arr = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
    if (arr){
        for (activimodel *a in arr) {
            if ([a.title isEqualToString:self.actie2.title]) {
                    NSString *title = NSLocalizedString(@"提示", nil);
                    NSString *message = NSLocalizedString(@"收藏成功", nil);
                    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
                    [self presentViewController:alertController animated:YES completion:nil];
                
                NSLog(@"收藏成功");
                //2秒后调用 diss
                //参数1:执行的方法
                //参数2: 执行方法时传递的参数
                //参数3: 延迟的时间
                [self performSelector:@selector(diss:) withObject:@"ssss" afterDelay:2];
//                 self.timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(roll) userInfo:nil repeats:YES];
                return;
            }
        }
        [arr addObject:self.actie2];
    }
    else
    {
        arr = [NSMutableArray array];
        NSString *title = NSLocalizedString(@"提示", nil);
        NSString *message = NSLocalizedString(@"收藏成功", nil);
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alertController animated:YES completion:nil];
        [self performSelector:@selector(diss:) withObject:@"ssss" afterDelay:2];
//         self.timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(roll) userInfo:nil repeats:YES];
        [arr addObject:self.actie2];
    }
    [NSKeyedArchiver archiveRootObject:arr toFile:path];
    
    
    
}

- (void)diss:(id)a
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
//- (void)roll
//{
//    [self dismissViewControllerAnimated:YES completion:^{
//        
//    }];
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.MOvietitle.text = self.actie2.title;
    self.Begintime.text = self.actie2.begin_time;
    self.Endtime.text = self.actie2.end_time;
    self.address.text = self.actie2.address;
    self.type.text = self.actie2.category_name;
    self.content.text = self.actie2.content;
    [self.touxiang sd_setImageWithURL:[NSURL URLWithString:self.actie2.image]];

    self.person.text =self.actie2.name;
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
